/**
 * This file is part of the dspace-poltman project http://www.poltman.com.
 *
 * This is free software; you can redistribute it and/or modify it under
 * the terms of DuraSpace DSpace license detailed in the LICENSE and NOTICE 
 * files at the root of the source tree and available online at
 * http://www.dspace.org/license/
 * 
 */

package com.poltman.dscentral.login;

import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;
import org.zkoss.bind.annotation.Init;
import org.zkoss.zkplus.spring.SpringUtil;

import com.poltman.dscentral.db.entity.pm.LanguagesEntity;
import com.poltman.dscentral.db.service.pm.LanguagesService;

import com.poltman.dscentral.core.CoreSessionData;
import com.poltman.dscentral.core.webappinit.WebAppInit;

/**
 * 
 * @author z.ciok@poltman.com
 * @version $Revision: 1425 $
 *
 */
public class LoginVM {
	
	private static Logger log = Logger.getLogger(LoginVM.class);

	private List<String> languagesNames;
	
	@Init
	public void init() throws Exception {
		CoreSessionData coreSessionData = (CoreSessionData) SpringUtil.getBean("coreSessionData");
		if (coreSessionData == null) {
			log.error("coreSessionData == null");
			throw new Exception("Bean coreSessionData is null");
		} else {
			String defaultLanguage = WebAppInit.getInstance().getDefaultLanguage();
			coreSessionData.setSelectedLanguageCode(defaultLanguage);
			log.info("LoginVM; default.language = " + coreSessionData.getSelectedLanguageCode());
		}
		
		LanguagesService  languagesService = (LanguagesService) SpringUtil.getBean("languagesService");
		List<LanguagesEntity> languages = languagesService.findByImplemented(true);
		languagesNames = new ArrayList<String>();
		for (LanguagesEntity langs : languages) languagesNames.add(langs.getName());
	}

	public List<String> getLanguagesNames() {
		return languagesNames;
	}

	public void setLanguagesNames(List<String> languagesNames) {
		this.languagesNames = languagesNames;
	}
}
